package com.itheima.web.exceptions;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * springmvc,处理异常类
 */
@Component
public class ExceptionResolver implements HandlerExceptionResolver{
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        ModelAndView mv=new ModelAndView();
        mv.setViewName("error");
        if (e instanceof CustomerExcetion){
            //自定义异常
            mv.addObject("errorMsg",e.getMessage());
        }else {
            //系统异常
            mv.addObject("errorMsg","服务器忙");
            e.printStackTrace();
        }
        return mv;
    }
}
